/**
 * Copyright (C) 2013-2014 the original author or authors.
 */
package com.foreveross.bsl.mam.rbac.application;

import java.util.List;

import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import org.springframework.data.domain.Page;

import com.foreveross.bsl.mam.rbac.application.vo.RbacUserRoleVO;
import com.foreveross.bsl.mam.rbac.application.vo.RoleVO;
import com.foreveross.bsl.mam.rbac.application.vo.UserVO;

/**
 * <BR>
 * [功能详细描述]
 * 
 * @author Amberlo
 * @version [mam-application , 2013-6-27]
 */
@Path(value = "/rbacUserRole")
@Produces(MediaType.APPLICATION_JSON)
public interface RbacUserRoleApplication {

	@POST
	@Path("/add")
	public RbacUserRoleVO saveEntity(RbacUserRoleVO entity);

	@PUT
	@Path("/update")
	public RbacUserRoleVO updateEntity(RbacUserRoleVO entity);

	public void deleteEntity(RbacUserRoleVO entity);

	@GET
	@Path("/userroles/{id}")
	public RbacUserRoleVO getEntity(@PathParam("id") String id);

	@GET
	@Path("/userroles")
	public List<RbacUserRoleVO> findAll();

	@GET
	@Path("/userroles/{pageNumber}/{pageSize}")
	public Page<RbacUserRoleVO> findByPage(@PathParam("pageNumber") int pageNumber, @PathParam("pageSize") int pageSize);

	// 自定义方法
	/** 根据用户id获取关联角色 */
	@GET
	@Path("/users-roles")
	public List<RoleVO> getRolesByUserID(@QueryParam("userID") String userID);

	/** 根据角色id获取关联用户 */
	@GET
	@Path("/roles-users")
	public List<UserVO> getUsersByRoleID(@QueryParam("roleID") String roleID);

	/** 根据角色id获取该角色没有的用户 */
	@GET
	@Path("/none-roles-users")
	public List<UserVO> getMoreRoleUser(@QueryParam("roleID") String roleID);

	@DELETE
	@Path("/delete")
	public void deleteByUserId(@QueryParam("userId") String userId);

	@DELETE
	@Path("/delete-by-roleid")
	public void deleteByRoleId(@QueryParam("roleId") String roleId);

	/**
	 * 给角色关联用户
	 * @param roleID
	 * @param usersID
	 */
	@POST
	@Path("/assign-user-to-role")
	@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
	public void addUsersIdToRole(@FormParam("roleID") String roleID,  @FormParam("usersID") List<String> usersID);
	 
	/**
	 * 给用户关联角色
	 * @param roleID
	 * @param usersID
	 */
	@POST
	@Path("/assign-role-for-user")
	@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
	public void addRolesIDToUser(@FormParam("userID") String userID, @FormParam("rolesID")List<String> rolesID);

	/**
	 * @param userID
	 * @param rolesID
	 */
	@DELETE
	@Path("/delete-user-roles")
	public void deleteRolesIDToUser(@QueryParam("userID")String userID, @QueryParam("rolesID")String[] rolesID);

	/**
	 * @param roleID
	 * @param usersID
	 */
	@DELETE
	@Path("/delete-role-users")
	public void deleteUsersIDToRole(@QueryParam("roleID")String roleID, @QueryParam("usersID")String[] usersID);


    /* --------------  不经登陆验证接口  ---------------*/

    // 自定义方法
    /** 根据用户名获取关联角色 */
    @GET
    @Path("/findRolesByUserName")
    public List<RoleVO> getRolesByUserName(@QueryParam("appKey") String appKey, @QueryParam("username") String username);
}
